package com.ggh.jinjilive.ui.mine.personal.dressup;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityDressUpBinding;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.gyf.immersionbar.ImmersionBar;
import com.tencent.qcloud.tim.uikit.utils.ScreenUtil;

import java.util.ArrayList;
import java.util.List;

@Route(path = ARouterUtils.DressUpActivity)
public class DressUpActivity extends BaseActivity<ActivityDressUpBinding> {

    private String[] mFragmentTitles = {"头像框", "座驾"};
    private int[] mFragmentStatus = {1, 2};


    private List<DressUpFragment> dressUpFragmentList = new ArrayList<>();
    //适配器
    private ProfitOrderAdapter profitOrderAdapter;
    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_dress_up;
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("个人装扮",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, ScreenUtil.getStatusBarHeight(),0,0);
    }

    @Override
    public void initData() {
        super.initData();
        for (int i = 0; i < mFragmentTitles.length; i++) {
           DressUpFragment dressUpFragment = new DressUpFragment(mFragmentStatus[i]);
            dressUpFragmentList.add(dressUpFragment);
        }
        profitOrderAdapter = new ProfitOrderAdapter(getSupportFragmentManager());
        binding.orderVp.setAdapter(profitOrderAdapter);
        binding.orderVp.setOffscreenPageLimit(mFragmentTitles.length);
        binding.stlOrder.setViewPager(binding.orderVp, mFragmentTitles);
        binding.orderVp.setCurrentItem(0);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

    }


    class ProfitOrderAdapter extends FragmentPagerAdapter {
        public DressUpFragment dressUpFragment;

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public DressUpFragment getItem(int position) {
            return dressUpFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return dressUpFragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            dressUpFragment = (DressUpFragment) object;
            super.setPrimaryItem(container, position, object);
        }
    }
}
